home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / video / xevil-1.000 / xevil-1 / intel.h < prev    next >
C/C++ Source or Header  |  1995-07-24  |  10KB  |  377 lines

  1. // "intel.h"
  2. // TAG: IT
  3.  
  4. /*    Copyright (C) 1994  Steve Hardt
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 1, or (at your option)
  9.     any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     Steve Hardt 
  21.     hardts@athena.mit.edu hardts@media.mit.edu
  22.     hardts@r4002.3dem.bioch.bcm.tmc.edu
  23.     2043 McClendon
  24.     Houston, TX 77030
  25. */
  26.  
  27. #ifndef INTEL_H
  28. #define INTEL_H
  29.  
  30. #ifndef NO_PRAGMAS
  31. #pragma interface
  32. #endif
  33.  
  34.  
  35. // Include Files
  36. #include "utils.h"
  37. #include "coord.h"
  38. #include "id.h"
  39. #include "locator.h"
  40. #include "world.h"
  41.  
  42.  
  43.  
  44. // Defines
  45. #define IT_STRING_LENGTH 80
  46. #define IT_INFINITE_LIVES -1
  47.  
  48.  
  49. class Physical;
  50. typedef Physical *PhysicalP;
  51.  
  52.  
  53. /* Possible commands to be given to objects.
  54.    Order of directions is guaranteed.  (See ui.h and game.C) */
  55.   enum {
  56.     IT_CENTER,
  57.     IT_R, IT_DN_R, IT_DN, IT_DN_L,
  58.     IT_L, IT_UP_L, IT_UP, IT_UP_R,
  59.     IT_WEAPON_CENTER,IT_WEAPON_CHANGE,IT_WEAPON_DROP,
  60.     IT_ITEM_USE,IT_ITEM_CHANGE,IT_ITEM_DROP,
  61.     
  62.     IT_WEAPON_R,IT_WEAPON_DN_R,IT_WEAPON_DN,IT_WEAPON_DN_L,
  63.     IT_WEAPON_L,IT_WEAPON_UP_L,IT_WEAPON_UP,IT_WEAPON_UP_R,
  64.  
  65.     IT_NO_COMMAND};
  66. typedef int ITcommand;
  67. #define IT_COMMAND_MAX IT_NO_COMMAND
  68.  
  69.  
  70.  
  71. // IntelOptions
  72. typedef unsigned long ITmask;
  73. #define ITnone 0L
  74. #define ITharmless (1L<<0)
  75. #define ITclassFriends (1L<<1)
  76. #define ITpsychotic (1L<<2)
  77. #define ITignoreItems (1L<<3)
  78. #define ITignoreLemmings (1L<<4)
  79.  
  80. struct IntelOptions {
  81.   Boolean classFriends; // Do not attack members of same class.
  82.   Boolean harmless; // Will not attack even if it has the ability to do so.
  83.   Boolean psychotic; // Will never run away.  harmless overrides psychotic.
  84.   Boolean ignoreItems; // Don't try to pick up items.
  85.   Boolean ignoreLemmings; // Don't attack Lemmings.
  86. };
  87.  
  88.  
  89.  
  90. // IntelStatus used by ui.
  91. // Remember Intel::die
  92. struct IntelStatus {
  93.   // strings and ClassIds must be kept consistent.
  94.  
  95.   char name[IT_STRING_LENGTH];
  96.   ClassId classId;
  97.   char clas[IT_STRING_LENGTH];
  98.   Health health; // -1 means dead.
  99.   Mass mass;
  100.   ClassId weaponClassId;  
  101.   char weapon[IT_STRING_LENGTH];
  102.   Boolean weaponReady;
  103.   int ammo;
  104.   ClassId itemClassId;
  105.   char item[IT_STRING_LENGTH];
  106.   int lives; // Can be IT_INFINITE_LIVES.
  107.   int humanKills;
  108.   int enemyKills;
  109.   int soups; // Human killed by something other than a human.  Only looked at
  110.              // when game style is UIsettings::DUEL.
  111. };
  112.  
  113.   
  114.  
  115. // Class Definitions.
  116. class Intel {
  117.  public:
  118.   Intel(WorldP w,LocatorP l,char *name,int lives,
  119.     const IntelOptions *ops,ITmask opMask); 
  120.   /* EFFECTS: Create a new intel with the options specified in opMakse that are
  121.      in ops.  ops will never be referenced if opMask is ITnone.  lives are
  122.      decremented as human is created.  lives can also be set to 
  123.      IT_INFINTE_LIVES. */
  124.  
  125.   virtual Boolean is_human();
  126.   /* NOTE: !is_human() iff Intel is a Machine. */
  127.   virtual Boolean is_enemy();
  128.   virtual Boolean is_lemming_intel();
  129.  
  130.   Boolean alive() {return living;}
  131.   WorldP get_world() {return world;}
  132.   LocatorP get_locator() {return locator;}
  133.  
  134.   const Id &get_id() {return id;}
  135.   /* NOTE: If dead, return an invalid id. */
  136.  
  137.   Boolean reincarnate_me();
  138.   /* EFFECTS: Should *this be reincarnated. */
  139.  
  140.   Boolean intel_status_changed() {return intelStatusChanged;}
  141.  
  142.   const IntelStatus *get_intel_status() 
  143.     {intelStatusChanged = False; return &intelStatus;}
  144.  
  145.   const char *get_name() {return intelStatus.name;}
  146.   int get_lives() {return intelStatus.lives;} // Can be IT_INFINITE_LIVES.
  147.   int get_human_kills() {return intelStatus.humanKills;}
  148.   int get_enemy_kills() {return intelStatus.enemyKills;}
  149.   int get_soups() {return intelStatus.soups;}
  150.   /* NOTE: Could achieve the same thing with get_intel_status.  Convenience 
  151.    functions. */
  152.  
  153.   IntelId get_killer_intel_id() {return killerIntelId;}
  154.  
  155.   IntelId get_intel_id() {return intelId;}
  156.  
  157.   void set_id(const Id &i) {id = i;}
  158.   /* REQUIRES: i is valid. */
  159.   /* NOTE: Only needed for Physical::set_intel.  id is updated on every 
  160.      clock. */
  161.  
  162.   void set_lives(int lives) 
  163.     {intelStatus.lives = lives; intelStatusChanged = True;}
  164.   /* NOTE: Can be IT_INFINITE_LIVES. */
  165.  
  166.   virtual void add_human_kill();
  167.  
  168.   virtual void add_enemy_kill();
  169.  
  170.   virtual void add_soup();
  171.  
  172.   void set_killer_intel_id(const IntelId &k) {killerIntelId = k;}
  173.  
  174.   void set_intel_id(const IntelId &i) {intelId = i;}
  175.   /* NOTE: Should only be used by the Locator. */
  176.  
  177.   static ITcommand dir_to_command(Dir dir);
  178.   /* REQUIRES: dir is a "pure" direction or CO_air. */
  179.   /* NOTE: CO_air -> IT_CENTER. */
  180.  
  181.   static ITcommand dir_to_command_weapon(Dir dir);
  182.  
  183.   static Dir command_weapon_to_dir_4(ITcommand);
  184.  
  185.   static Dir command_weapon_to_dir_8(ITcommand);
  186.   /* EFFECTS: If command is a weapon command return the corresponding Dir. */
  187.   /* NOTE: Like Gun::compute_weapon_dir. */
  188.  
  189.   static Boolean is_command_weapon(ITcommand command)
  190.     {return (command >= IT_WEAPON_R && command <= IT_WEAPON_UP_R) || 
  191.        command == IT_WEAPON_CENTER;}
  192.  
  193.   static ITcommand center_pos_to_command(const Pos &pos);
  194.   /* EFFECTS: Returns the command corresponding to the direction from (0,0) to
  195.      pos. */
  196.   /* NOTE: pos can have negative components. */
  197.      
  198.  
  199.   void die(); 
  200.   /* EFFECTS: Tell *this that it no longer has anything clocking it. */
  201.   /* NOTE: This MUST be called at death.  Game requires it to refill enemy
  202.      players. */
  203.  
  204.   void reincarnate();
  205.   /* EFFECTS: Tell *this that it will be clocked again. */
  206.  
  207.   virtual void clock(PhysicalP p);
  208.   /* NOTE: Should be called by Intel's children. */
  209.  
  210.  
  211. #ifndef PROTECTED_IS_PUBLIC
  212.  protected:
  213. #endif
  214.   const IntelOptions &get_intel_options() {return intelOptions;}
  215.  
  216.  
  217.  private:
  218.   IntelStatus intelStatus;
  219.   Boolean intelStatusChanged; // Since last get_intel_status.
  220.   Boolean living;
  221.   WorldP world;
  222.   LocatorP locator;
  223.   Id id;
  224.   IntelId killerIntelId;  // Intel that most recently attacked the Intel.
  225.   IntelId intelId;
  226.   IntelOptions intelOptions;
  227.  
  228.   const static IntelOptions intelOptionsDefault;
  229. };
  230. typedef Intel *IntelP;
  231.  
  232.  
  233.  
  234. // Simply buffers input from a user interface.
  235. class Human: public Intel {
  236.  public: 
  237.   Human(WorldP w,LocatorP l,char *name,int lives,ColorNum colorNum);
  238.   /* NOTE: Uses all default options.  intelOptions should be meaningless for 
  239.      a human. */
  240.  
  241.   ColorNum get_color_num() {return colorNum;}
  242.  
  243.   virtual Boolean is_human();
  244.     
  245.   void set_command(ITcommand c) {command = c;}
  246.   /* EFFECTS: Asynchronously set the command for the current turn to be c.
  247.      Overrides previous settings. */
  248.  
  249.   virtual void clock(PhysicalP p);
  250.   /* EFFECTS: Sets the command for p. */
  251.  
  252.  
  253.  private:
  254.   ITcommand command;
  255.   ColorNum colorNum;
  256. };
  257. typedef Human *HumanP;
  258.  
  259.  
  260.  
  261. class Machine: public Intel {
  262.   enum Strategy {doNothing, toPos, toTarget, awayTarget, toMaster};
  263.   
  264. public:
  265.   Machine(WorldP w,LocatorP l,char *name,
  266.       const IntelOptions *ops,ITmask opMask,
  267.       IntelP master = NULL);
  268.   
  269.   Boolean is_slave() {return !masterSet;}
  270.  
  271.   IntelId get_master_intel_id();
  272.   /* EFFECTS: If a slave, return the IntelId of the master.  Otherwise, 
  273.      return an invalid IntelId. */
  274.  
  275.   virtual void add_human_kill();
  276.  
  277.   virtual void add_enemy_kill();
  278.  
  279.   virtual void add_soup();
  280.  
  281.   virtual void clock(PhysicalP);
  282.   /* NOTE: Not called by Machine's children. */
  283.  
  284.  
  285. #ifndef PROTECTED_IS_PUBLIC
  286. protected:
  287. #endif
  288.   static Boolean attack_target(PhysicalP p,PhysicalP target);
  289.   static Boolean move_target(PhysicalP p,PhysicalP target,Timer &ladderJump);
  290.   static Boolean away_target(PhysicalP p,PhysicalP target,Timer &ladderJump);
  291.   static Boolean move_pos(PhysicalP p,const Pos &targetPos,Timer &ladderJump);
  292.   static Boolean move_dir(PhysicalP p,Dir d,Timer &ladderJump);
  293.   /* REQUIRES: p and target must be non-NULL. */
  294.   /* REQUIRES: d is an element of {CO_R..CO_UP_R,CO_air} */
  295.   /* EFFECTS: The above are all utility functions that attempt to set the
  296.      command for p to do something.  Returns whether the command was set or
  297.      not. */
  298.   /* IMPLEMENTATION NOTE: Declared static to ensure that no data members of 
  299.      Machine are used in these utility functions.  We */
  300.  
  301.  
  302.   static Boolean has_gun(PhysicalP);
  303.   static Boolean has_cutter(PhysicalP);
  304.   static Boolean has_shield(PhysicalP);
  305.   static Boolean has_item(PhysicalP,ClassId);
  306.   static Boolean weapon_current_is_gun(PhysicalP);
  307.   static Boolean weapon_current_is_cutter(PhysicalP);
  308.   /* EFFECTS: Return info about a Physical. */
  309.  
  310.  
  311. private:
  312.   PhysicalP new_target_id(Boolean &isEnemy,PhysicalP p,PhysicalP masterP);
  313.   /* MODIFIES: isItem */
  314.   /* EFFECTS: Get a new target for p.  Sets targetId, sets isEnemy to True iff
  315.      returned pointer is an enemy (as opposed to an item).
  316.      Returns NULL if no suitable target found.  masterP is the master's
  317.      Physical or NULL. */
  318.  
  319.  
  320.   IntelId masterIntelId; // Meaningful iff masterSet.
  321.   Boolean masterSet; // Is the Machine a slave to another Intel.
  322.   Strategy strategy;
  323.   Pos targetPos;
  324.   Id targetId;
  325.   Timer strategyChange;
  326.   Timer reflexes;
  327.   Timer ladderJump; // don't get back on ladder immediately after jumping off.
  328. };
  329. typedef Machine *MachineP;
  330.  
  331.  
  332.  
  333. class Enemy: public Machine {
  334. public:
  335.   Enemy(WorldP w,LocatorP l,char *name,
  336.     const IntelOptions *ops,ITmask opMask,
  337.     IntelP master = NULL)
  338.     :Machine(w,l,name,ops,opMask,master) {}
  339.   
  340.   virtual Boolean is_enemy();
  341. };
  342. typedef Enemy *EnemyP;
  343.  
  344.  
  345.  
  346.  
  347. class Neutral: public Machine {
  348. public:
  349.   Neutral(WorldP w,LocatorP l,char *name,
  350.     const IntelOptions *ops,ITmask opMask,
  351.     IntelP master = NULL)
  352.     :Machine(w,l,name,ops,opMask,master) {}
  353.   
  354.   virtual Boolean is_enemy();
  355. };
  356. typedef Neutral *NeutralP;
  357.  
  358.  
  359.  
  360.  
  361. class LemmingIntel: public Neutral {
  362. public:
  363.   LemmingIntel(WorldP w,LocatorP l,char *name,const Id &homeId);
  364.   
  365.   virtual Boolean is_lemming_intel();
  366.  
  367.   virtual void clock(PhysicalP);
  368.   /* NOTE: Does not call Neutral::clock. */
  369.   
  370.  
  371.  private:
  372.   Timer ladderJump; // don't get back on ladder immediately after jumping off.
  373.   Id homeId;
  374. };
  375. #endif
  376.  
  377.